import 'package:flutter/material.dart';
// Directions
// Create the button
// Wrap it in a GestureDetector with an onTap callback

class ImplementSwipe2DismissDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Implement Swipe to Dismiss Demo'),
      ),
      body: MyButton(),
    );
  }
}

class MyButton extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MyButtonState();
  }
}

class _MyButtonState extends State<MyButton> {
  final items = List<String>.generate(20, (i) => "Item ${i + 1}");

  @override
  Widget build(BuildContext context) {
    // The InkWell Wraps our custom flat button Widget
    return ListView.builder(
      itemCount: items.length,
      itemBuilder: (context, index) {
        final item = items[index];
        return Dismissible(
          direction: DismissDirection.vertical,
          background: Container(color: Colors.red),
          // Each Dismissible must contain a Key. Keys allow Flutter to
          // uniquely identify Widgets.
          key: Key(item),
          // We also need to provide a function that will tell our app
          // what to do after an item has been swiped away.
          onDismissed: (direction) {
            // Remove the item from our data source.
            setState(() {
              items.removeAt(index);
            });

            // Show a snackbar! This snackbar could also contain "Undo" actions.
            Scaffold.of(context)
                .showSnackBar(SnackBar(content: Text("$item dismissed")));
          },
          child: ListTile(title: Text('$item')),
        );
        ;
      },
    );
  }
}
